
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Go 错误处理 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../part22/" />
    
    
    <link rel="prev" href="../part20/" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../part1/">
            
                <a href="../part1/">
            
                    
                    Go 语言简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../part2/">
            
                <a href="../part2/">
            
                    
                    Go 语言环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../part3/">
            
                <a href="../part3/">
            
                    
                    Go 语言结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../part4/">
            
                <a href="../part4/">
            
                    
                    Go 语言基础语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../part5/">
            
                <a href="../part5/">
            
                    
                    Go 语言数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../part6/">
            
                <a href="../part6/">
            
                    
                    Go 语言变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../part7/">
            
                <a href="../part7/">
            
                    
                    Go 语言常量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../part8/">
            
                <a href="../part8/">
            
                    
                    Go 语言运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../part9/">
            
                <a href="../part9/">
            
                    
                    Go 语言条件语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../part10/">
            
                <a href="../part10/">
            
                    
                    Go 语言循环语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../part11/">
            
                <a href="../part11/">
            
                    
                    Go 语言函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../part12/">
            
                <a href="../part12/">
            
                    
                    Go 语言数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../part13/">
            
                <a href="../part13/">
            
                    
                    Go 语言指针
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../part14/">
            
                <a href="../part14/">
            
                    
                    Go 语言结构体
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../part15/">
            
                <a href="../part15/">
            
                    
                    Go 语言切片(Slice)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../part16/">
            
                <a href="../part16/">
            
                    
                    Go 语言范围(Range)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../part17/">
            
                <a href="../part17/">
            
                    
                    Go 语言Map(集合)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../part18/">
            
                <a href="../part18/">
            
                    
                    Go 语言递归函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../part19/">
            
                <a href="../part19/">
            
                    
                    Go 语言类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../part20/">
            
                <a href="../part20/">
            
                    
                    Go 语言接口
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.22" data-path="./">
            
                <a href="./">
            
                    
                    Go 错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="../part22/">
            
                <a href="../part22/">
            
                    
                    Go 并发
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Go 错误处理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="go-&#x9519;&#x8BEF;&#x5904;&#x7406;">Go &#x9519;&#x8BEF;&#x5904;&#x7406;</h1>
<p>Go &#x8BED;&#x8A00;&#x901A;&#x8FC7;&#x5185;&#x7F6E;&#x7684;&#x9519;&#x8BEF;&#x63A5;&#x53E3;&#x63D0;&#x4F9B;&#x4E86;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x7684;&#x9519;&#x8BEF;&#x5904;&#x7406;&#x673A;&#x5236;&#x3002;</p>
<p>error&#x7C7B;&#x578B;&#x662F;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x7C7B;&#x578B;&#xFF0C;&#x8FD9;&#x662F;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> error <span class="hljs-keyword">interface</span> {
    Error() <span class="hljs-keyword">string</span>
}
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x7F16;&#x7801;&#x4E2D;&#x901A;&#x8FC7;&#x5B9E;&#x73B0; error &#x63A5;&#x53E3;&#x7C7B;&#x578B;&#x6765;&#x751F;&#x6210;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x901A;&#x5E38;&#x5728;&#x6700;&#x540E;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4E2D;&#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;&#x4F7F;&#x7528;errors.New &#x53EF;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x5728;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x8C03;&#x7528;Sqrt&#x7684;&#x65F6;&#x5019;&#x4F20;&#x9012;&#x7684;&#x4E00;&#x4E2A;&#x8D1F;&#x6570;&#xFF0C;&#x7136;&#x540E;&#x5C31;&#x5F97;&#x5230;&#x4E86;<code>non-nil</code>&#x7684;error&#x5BF9;&#x8C61;&#xFF0C;&#x5C06;&#x6B64;&#x5BF9;&#x8C61;&#x4E0E;nil&#x6BD4;&#x8F83;&#xFF0C;&#x7ED3;&#x679C;&#x4E3A;true&#xFF0C;&#x6240;&#x4EE5;fmt.Println(fmt&#x5305;&#x5728;&#x5904;&#x7406;error&#x65F6;&#x4F1A;&#x8C03;&#x7528;Error&#x65B9;&#x6CD5;)&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x4EE5;&#x8F93;&#x51FA;&#x9519;&#x8BEF;&#xFF0C;&#x8BF7;&#x770B;&#x4E0B;&#x9762;&#x8C03;&#x7528;&#x7684;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> (
    <span class="hljs-string">&quot;errors&quot;</span>
    <span class="hljs-string">&quot;fmt&quot;</span>
)

<span class="hljs-keyword">func</span> Sqrt(f <span class="hljs-keyword">float64</span>) (<span class="hljs-keyword">float64</span>, error) {
    <span class="hljs-keyword">if</span> f &lt; <span class="hljs-number">0</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>, errors.New(<span class="hljs-string">&quot;math: square root of negative number&quot;</span>)
    }
    <span class="hljs-comment">// &#x5B9E;&#x73B0;</span>
    <span class="hljs-keyword">return</span> f, <span class="hljs-literal">nil</span>
}

<span class="hljs-keyword">func</span> main() {
    a := <span class="hljs-number">-4.0</span>
    b, err := Sqrt(a)
    fmt.Println(b)
    <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
        fmt.Println(err)
    }
}
</code></pre>
<p>&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>


<span class="hljs-comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A; DivideError &#x7ED3;&#x6784;</span>
<span class="hljs-keyword">type</span> DivideError <span class="hljs-keyword">struct</span> {
    dividee <span class="hljs-keyword">int</span>
    divider <span class="hljs-keyword">int</span>
}

<span class="hljs-comment">// &#x5B9E;&#x73B0; `error` &#x63A5;&#x53E3;</span>
<span class="hljs-keyword">func</span> (de *DivideError) Error() <span class="hljs-keyword">string</span> {
    strFormat := <span class="hljs-string">`
    Cannot proceed, the divider is zero.
    dividee: %d
    divider: 0
`</span>
    <span class="hljs-keyword">return</span> fmt.Sprintf(strFormat, de.dividee)
}

<span class="hljs-comment">// &#x5B9A;&#x4E49; `int` &#x7C7B;&#x578B;&#x9664;&#x6CD5;&#x8FD0;&#x7B97;&#x7684;&#x51FD;&#x6570;</span>
<span class="hljs-keyword">func</span> Divide(varDividee <span class="hljs-keyword">int</span>, varDivider <span class="hljs-keyword">int</span>) (result <span class="hljs-keyword">int</span>, errorMsg <span class="hljs-keyword">string</span>) {
    <span class="hljs-keyword">if</span> varDivider == <span class="hljs-number">0</span> {
        dData := DivideError{
            dividee: varDividee,
            divider: varDivider,
        }
        errorMsg = dData.Error()
        <span class="hljs-keyword">return</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> varDividee / varDivider, <span class="hljs-string">&quot;&quot;</span>
    }
}

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">// &#x6B63;&#x5E38;&#x60C5;&#x51B5;</span>
    <span class="hljs-keyword">if</span> result, errorMsg := Divide(<span class="hljs-number">100</span>, <span class="hljs-number">10</span>); errorMsg == <span class="hljs-string">&quot;&quot;</span> {
        fmt.Println(<span class="hljs-string">&quot;100/10 = &quot;</span>, result)
    }
    <span class="hljs-comment">// &#x5F53;&#x9664;&#x6570;&#x4E3A;&#x96F6;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x4FE1;&#x606F;</span>
    <span class="hljs-keyword">if</span> _, errorMsg := Divide(<span class="hljs-number">100</span>, <span class="hljs-number">0</span>); errorMsg != <span class="hljs-string">&quot;&quot;</span> {
        fmt.Println(<span class="hljs-string">&quot;errorMsg is: &quot;</span>, errorMsg)
    }
}
</code></pre>
<pre><code class="lang-sh">100/10 =  10
errorMsg is:  
    Cannot proceed, the divider is zero.
    dividee: 100
    divider: 0
</code></pre>
<hr>
<h2 id="ps">PS</h2>
<ol>
<li><p>ex1</p>
<pre><code class="lang-go"> <span class="hljs-keyword">package</span> main

 <span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

 <span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
     username <span class="hljs-keyword">string</span>
     password <span class="hljs-keyword">string</span>
 }

 <span class="hljs-keyword">func</span> (p *User) init(username <span class="hljs-keyword">string</span> ,password <span class="hljs-keyword">string</span>) (*User, <span class="hljs-keyword">string</span>)  {
     <span class="hljs-keyword">if</span> username == <span class="hljs-string">&quot;&quot;</span> || password == <span class="hljs-string">&quot;&quot;</span> {
         <span class="hljs-keyword">return</span> p, p.Error()
     }
     p.username = username
     p.password = password
     <span class="hljs-keyword">return</span> p, <span class="hljs-string">&quot;&quot;</span>
 }

 <span class="hljs-keyword">func</span> (p *User) Error() <span class="hljs-keyword">string</span> {
     <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;username or password shouldn&apos;t be empty!&quot;</span>
 }

 <span class="hljs-keyword">func</span> main() {
     <span class="hljs-keyword">var</span> user User
     user1, _ := user.init(<span class="hljs-string">&quot;&quot;</span>,<span class="hljs-string">&quot;&quot;</span>)
     fmt.Println(user1)
 }
</code></pre>
</li>
<li><p>ex2 </p>
<pre><code class="lang-go"> <span class="hljs-keyword">package</span> main

 <span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

 <span class="hljs-comment">// &#x81EA;&#x5B9A;&#x4E49;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x7ED3;&#x6784;</span>
 <span class="hljs-keyword">type</span> DivErr <span class="hljs-keyword">struct</span> {
     etype <span class="hljs-keyword">int</span>  <span class="hljs-comment">// &#x9519;&#x8BEF;&#x7C7B;&#x578B;</span>
     v1 <span class="hljs-keyword">int</span>     <span class="hljs-comment">// &#x8BB0;&#x5F55;&#x4E0B;&#x51FA;&#x9519;&#x65F6;&#x7684;&#x9664;&#x6570;&#x3001;&#x88AB;&#x9664;&#x6570;</span>
     v2 <span class="hljs-keyword">int</span>
 }
 <span class="hljs-comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5; error.Error()</span>
 <span class="hljs-keyword">func</span> (divErr DivErr) Error() <span class="hljs-keyword">string</span> {
     <span class="hljs-keyword">if</span> <span class="hljs-number">0</span> == divErr.etype {
         <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x9664;&#x96F6;&#x9519;&#x8BEF;&quot;</span>
     }<span class="hljs-keyword">else</span>{
         <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x5176;&#x4ED6;&#x672A;&#x77E5;&#x9519;&#x8BEF;&quot;</span>
     }
 }
 <span class="hljs-comment">// &#x9664;&#x6CD5;</span>
 <span class="hljs-keyword">func</span> div(a <span class="hljs-keyword">int</span>, b <span class="hljs-keyword">int</span>) (<span class="hljs-keyword">int</span>, *DivErr) {
     <span class="hljs-keyword">if</span> b == <span class="hljs-number">0</span> {
         <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x4FE1;&#x606F;</span>
         <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>, &amp;DivErr{<span class="hljs-number">0</span>,a,b}
     } <span class="hljs-keyword">else</span> {
         <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6B63;&#x786E;&#x7684;&#x5546;</span>
         <span class="hljs-keyword">return</span> a / b, <span class="hljs-literal">nil</span>
     }
 }
 <span class="hljs-keyword">func</span> main() {
     <span class="hljs-comment">// &#x6B63;&#x786E;&#x8C03;&#x7528;</span>
     v, r := div(<span class="hljs-number">100</span>,<span class="hljs-number">2</span>)
     <span class="hljs-keyword">if</span> <span class="hljs-literal">nil</span> != r {
         fmt.Println(<span class="hljs-string">&quot;(1)fail:&quot;</span>, r)
     }<span class="hljs-keyword">else</span>{
         fmt.Println(<span class="hljs-string">&quot;(1)succeed:&quot;</span>, v)
     }
     <span class="hljs-comment">// &#x9519;&#x8BEF;&#x8C03;&#x7528;</span>
     v, r = div(<span class="hljs-number">100</span>,<span class="hljs-number">0</span>)
     <span class="hljs-keyword">if</span> <span class="hljs-literal">nil</span>!=r{
         fmt.Println(<span class="hljs-string">&quot;(2)fail:&quot;</span>, r)
     }<span class="hljs-keyword">else</span>{
         fmt.Println(<span class="hljs-string">&quot;(2)succeed:&quot;</span>, v)
     }
 }
</code></pre>
</li>
<li><p>ex3</p>
</li>
</ol>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x5F00;&#x59CB;&quot;</span>)
    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x51C6;&#x5907;recover&quot;</span>)
        <span class="hljs-keyword">if</span> err := <span class="hljs-built_in">recover</span>(); err != <span class="hljs-literal">nil</span> {
            fmt.Printf(<span class="hljs-string">&quot;%#v-%#v\n&quot;</span>, <span class="hljs-string">&quot;&#x5916;&#x5C42;&quot;</span>, err) <span class="hljs-comment">// err&#x5DF2;&#x7ECF;&#x5728;&#x4E0A;&#x4E00;&#x7EA7;&#x7684;&#x51FD;&#x6570;&#x4E2D;&#x6355;&#x83B7;&#x4E86;&#xFF0C;&#x8FD9;&#x91CC;&#x6CA1;&#x6709;&#x5F02;&#x5E38;&#xFF0C;&#x53EA;&#x662F;&#x4F8B;&#x884C;&#x5148;&#x6267;&#x884C;defer&#xFF0C;&#x7136;&#x540E;&#x6267;&#x884C;&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;</span>
        } <span class="hljs-keyword">else</span> {
            fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x6CA1;&#x505A;&#x5565;&#x4E8B;&quot;</span>)
        }
        fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x5B8C;&#x6210;recover&quot;</span>)
    }()
    fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x5373;&#x5C06;&#x5F02;&#x5E38;&quot;</span>)
    f()
    fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x5F02;&#x5E38;&#x540E;&quot;</span>)
    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5916;&#x5C42;&#x5F02;&#x5E38;&#x540E;defer&quot;</span>)
    }()
}

<span class="hljs-keyword">func</span> f() {
    fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x5F00;&#x59CB;&quot;</span>)
    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;recover&#x524D;&#x7684;defer&quot;</span>)
    }()

    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x51C6;&#x5907;recover&quot;</span>)
        <span class="hljs-keyword">if</span> err := <span class="hljs-built_in">recover</span>(); err != <span class="hljs-literal">nil</span> {
            fmt.Printf(<span class="hljs-string">&quot;%#v-%#v\n&quot;</span>, <span class="hljs-string">&quot;&#x5185;&#x5C42;&quot;</span>, err) <span class="hljs-comment">// &#x8FD9;&#x91CC;err&#x5C31;&#x662F;panic&#x4F20;&#x5165;&#x7684;&#x5185;&#x5BB9;</span>
        }

        fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x5B8C;&#x6210;recover&quot;</span>)
    }()

    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x5F02;&#x5E38;&#x524D;recover&#x540E;&#x7684;defer&quot;</span>)
    }()

    <span class="hljs-built_in">panic</span>(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x4FE1;&#x606F;&quot;</span>)

    <span class="hljs-keyword">defer</span> <span class="hljs-keyword">func</span>() {
        fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x5F02;&#x5E38;&#x540E;&#x7684;defer&quot;</span>)
    }()

    fmt.Println(<span class="hljs-string">&quot;&#x5185;&#x5C42;&#x5F02;&#x5E38;&#x540E;&#x8BED;&#x53E5;&quot;</span>) <span class="hljs-comment">//recover&#x6355;&#x83B7;&#x7684;&#x4E00;&#x7EA7;&#x6216;&#x8005;&#x5B8C;&#x5168;&#x4E0D;&#x6355;&#x83B7;&#x8FD9;&#x91CC;&#x5F00;&#x59CB;&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x4E0D;&#x4F1A;&#x518D;&#x6267;&#x884C;</span>
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../part20/" class="navigation navigation-prev " aria-label="Previous page: Go 语言接口">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../part22/" class="navigation navigation-next " aria-label="Next page: Go 并发">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Go 错误处理","level":"1.22","depth":1,"next":{"title":"Go 并发","level":"1.23","depth":1,"path":"part22/README.md","ref":"part22/README.md","articles":[]},"previous":{"title":"Go 语言接口","level":"1.21","depth":1,"path":"part20/README.md","ref":"part20/README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"part21/README.md","mtime":"2021-01-20T10:02:29.164Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-01-21T06:29:04.898Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

